package org.neuedu.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.neuedu.entity.DrugInfo;
import org.neuedu.mapper.DrugInfoMapper;
import org.neuedu.service.DrugInfoService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lzw
 * @since 2024-11-19
 */
@Service
public class DrugInfoServiceImpl extends ServiceImpl<DrugInfoMapper, DrugInfo> implements DrugInfoService {
    @Override
    public List<DrugInfo> list(String drugName, String mnemonicCode) {
        QueryWrapper<DrugInfo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(drugName)) {
            wrapper.like("drug_name", drugName);
        }
        if (StringUtils.isNotBlank(mnemonicCode)) {
            wrapper.likeRight("mnemonic_code", mnemonicCode);
        }
        return this.list(wrapper);
    }


    @Override
    public Boolean update(Integer id, BigDecimal drugPrice, Long quantity) {
        return this.updateById(new DrugInfo(id,drugPrice,quantity));
    }

    @Override
    public IPage<DrugInfo> listPage(Integer pageNo, Integer pageSize, String name) {
        QueryWrapper<DrugInfo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
            wrapper.like("drug_name", name);
        }
        wrapper.orderByDesc("id");
        return this.page(new Page<>(pageNo, pageSize), wrapper);
    }
}
